package com.wifirecommenderap;

import java.util.ArrayList;

import android.app.ListActivity;
import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.TextView;
import android.widget.ListView;
import android.widget.ArrayAdapter;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class ListViewActivity extends ListActivity
{
	//TextView title;
	//ListView lv;
	//Button bt;
	ArrayAdapter<String> lvadapter; 
	ListView lv;
	
	@Override
	public void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
				
		//getResources().getStringArray(R.array.temp_data);
		ArrayList<String> s = new ArrayList<String>();
		
		DBAdapter db = new DBAdapter(this);
	    db.open();
	    
	    // Grab Preferences to see what user wants
	    
	    Cursor cur = db.getAllTitles();
	    
	    for (int i = 0; i < 20; i++)
	    {
	    	cur.moveToPosition(i);	    	
	    	s.add(Integer.toString(i+1) + "  " + cur.getString(1) + " " + cur.getString(2) + " " + cur.getString(3));
	    }
		
		setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, s));
		
		//String[] test = new String[] {"A","B","C"};
		//lvadapter = new ArrayAdapter<String> (this, R.layout.list_item, s);
		//setListAdapter(lvadapter);
		
		lv = getListView();
		lv.setTextFilterEnabled(false);
		
		//title = (TextView)findViewById(R.id.listview_layout_title);
		//lv = (ListView)findViewById(R.id.listview_layout_listView);
		//bt = (Button)findViewById(R.id.listview_layout_contextSwitchButton);
		
        //bt.setOnClickListener(new Button.OnClickListener() 
        //{
        //	public void onClick(View v)
        //	{
        //		handlebtClick();
        //	}
        //});
		
        //populate the listview from some data
        //use R.arrays.temp_data
        
		//lv.setItemsCanFocus(false);
        //lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        
        //lv.setEmptyView(title);
        //lv.setAdapter(lvadapter);
       
        
  	  lv.setOnItemClickListener(new OnItemClickListener() {
  	    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  	      // When clicked, show a toast with the TextView text
  	      Toast.makeText(getApplicationContext(), ((TextView) view).getText(), Toast.LENGTH_SHORT).show();
  	    }
  	  });
        
        
	}
	/*
	public void handlebtClick()
	{
		//switch context (exit activity)
		finish();
	}
	*/
	
}
